package snapex.core.mapper;

import static org.mybatis.dynamic.sql.SqlBuilder.*;
import static snapex.core.mapper.ExpenseCashAdvanceDynamicSqlSupport.*;

import java.util.List;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.SqlBuilder;
import org.mybatis.dynamic.sql.delete.DeleteDSL;
import org.mybatis.dynamic.sql.delete.MyBatis3DeleteModelAdapter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.render.RenderingStrategy;
import org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter;
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
import org.mybatis.dynamic.sql.select.SelectDSL;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.MyBatis3UpdateModelAdapter;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import snapex.core.model.ExpenseCashAdvance;

@Mapper
public interface ExpenseCashAdvanceMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<ExpenseCashAdvance> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("ExpenseCashAdvanceResult")
    ExpenseCashAdvance selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="ExpenseCashAdvanceResult", value = {
        @Result(column="expense_id", property="expenseId", jdbcType=JdbcType.CHAR, id=true),
        @Result(column="cash_advance_id", property="cashAdvanceId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
        @Result(column="amount", property="amount", jdbcType=JdbcType.DECIMAL),
        @Result(column="currency", property="currency", jdbcType=JdbcType.CHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
        @Result(column="create_timestamp", property="createTimestamp", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="sync_timestamp", property="syncTimestamp", jdbcType=JdbcType.TIMESTAMP)
    })
    List<ExpenseCashAdvance> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<Long>> countByExample() {
        return SelectDSL.selectWithMapper(this::count, SqlBuilder.count())
                .from(expenseCashAdvance);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default DeleteDSL<MyBatis3DeleteModelAdapter<Integer>> deleteByExample() {
        return DeleteDSL.deleteFromWithMapper(this::delete, expenseCashAdvance);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(String expenseId_, String cashAdvanceId_) {
        return DeleteDSL.deleteFromWithMapper(this::delete, expenseCashAdvance)
                .where(expenseId, isEqualTo(expenseId_))
                .and(cashAdvanceId, isEqualTo(cashAdvanceId_))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(ExpenseCashAdvance record) {
        return insert(SqlBuilder.insert(record)
                .into(expenseCashAdvance)
                .map(expenseId).toProperty("expenseId")
                .map(cashAdvanceId).toProperty("cashAdvanceId")
                .map(remark).toProperty("remark")
                .map(amount).toProperty("amount")
                .map(currency).toProperty("currency")
                .map(status).toProperty("status")
                .map(createTimestamp).toProperty("createTimestamp")
                .map(syncTimestamp).toProperty("syncTimestamp")
                .build()
                .render(RenderingStrategy.MYBATIS3));
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(ExpenseCashAdvance record) {
        return insert(SqlBuilder.insert(record)
                .into(expenseCashAdvance)
                .map(expenseId).toPropertyWhenPresent("expenseId", record::getExpenseId)
                .map(cashAdvanceId).toPropertyWhenPresent("cashAdvanceId", record::getCashAdvanceId)
                .map(remark).toPropertyWhenPresent("remark", record::getRemark)
                .map(amount).toPropertyWhenPresent("amount", record::getAmount)
                .map(currency).toPropertyWhenPresent("currency", record::getCurrency)
                .map(status).toPropertyWhenPresent("status", record::getStatus)
                .map(createTimestamp).toPropertyWhenPresent("createTimestamp", record::getCreateTimestamp)
                .map(syncTimestamp).toPropertyWhenPresent("syncTimestamp", record::getSyncTimestamp)
                .build()
                .render(RenderingStrategy.MYBATIS3));
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<List<ExpenseCashAdvance>>> selectByExample() {
        return SelectDSL.selectWithMapper(this::selectMany, expenseId, cashAdvanceId, remark, amount, currency, status, createTimestamp, syncTimestamp)
                .from(expenseCashAdvance);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<List<ExpenseCashAdvance>>> selectDistinctByExample() {
        return SelectDSL.selectDistinctWithMapper(this::selectMany, expenseId, cashAdvanceId, remark, amount, currency, status, createTimestamp, syncTimestamp)
                .from(expenseCashAdvance);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default ExpenseCashAdvance selectByPrimaryKey(String expenseId_, String cashAdvanceId_) {
        return SelectDSL.selectWithMapper(this::selectOne, expenseId, cashAdvanceId, remark, amount, currency, status, createTimestamp, syncTimestamp)
                .from(expenseCashAdvance)
                .where(expenseId, isEqualTo(expenseId_))
                .and(cashAdvanceId, isEqualTo(cashAdvanceId_))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> updateByExample(ExpenseCashAdvance record) {
        return UpdateDSL.updateWithMapper(this::update, expenseCashAdvance)
                .set(expenseId).equalTo(record::getExpenseId)
                .set(cashAdvanceId).equalTo(record::getCashAdvanceId)
                .set(remark).equalTo(record::getRemark)
                .set(amount).equalTo(record::getAmount)
                .set(currency).equalTo(record::getCurrency)
                .set(status).equalTo(record::getStatus)
                .set(createTimestamp).equalTo(record::getCreateTimestamp)
                .set(syncTimestamp).equalTo(record::getSyncTimestamp);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> updateByExampleSelective(ExpenseCashAdvance record) {
        return UpdateDSL.updateWithMapper(this::update, expenseCashAdvance)
                .set(expenseId).equalToWhenPresent(record::getExpenseId)
                .set(cashAdvanceId).equalToWhenPresent(record::getCashAdvanceId)
                .set(remark).equalToWhenPresent(record::getRemark)
                .set(amount).equalToWhenPresent(record::getAmount)
                .set(currency).equalToWhenPresent(record::getCurrency)
                .set(status).equalToWhenPresent(record::getStatus)
                .set(createTimestamp).equalToWhenPresent(record::getCreateTimestamp)
                .set(syncTimestamp).equalToWhenPresent(record::getSyncTimestamp);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(ExpenseCashAdvance record) {
        return UpdateDSL.updateWithMapper(this::update, expenseCashAdvance)
                .set(remark).equalTo(record::getRemark)
                .set(amount).equalTo(record::getAmount)
                .set(currency).equalTo(record::getCurrency)
                .set(status).equalTo(record::getStatus)
                .set(createTimestamp).equalTo(record::getCreateTimestamp)
                .set(syncTimestamp).equalTo(record::getSyncTimestamp)
                .where(expenseId, isEqualTo(record::getExpenseId))
                .and(cashAdvanceId, isEqualTo(record::getCashAdvanceId))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(ExpenseCashAdvance record) {
        return UpdateDSL.updateWithMapper(this::update, expenseCashAdvance)
                .set(remark).equalToWhenPresent(record::getRemark)
                .set(amount).equalToWhenPresent(record::getAmount)
                .set(currency).equalToWhenPresent(record::getCurrency)
                .set(status).equalToWhenPresent(record::getStatus)
                .set(createTimestamp).equalToWhenPresent(record::getCreateTimestamp)
                .set(syncTimestamp).equalToWhenPresent(record::getSyncTimestamp)
                .where(expenseId, isEqualTo(record::getExpenseId))
                .and(cashAdvanceId, isEqualTo(record::getCashAdvanceId))
                .build()
                .execute();
    }
}